<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /**
         * 伪数组转化为数组的三种方式
         * 
         */
        function sum() {
            // 方式一： slice(0)
            // var newArr = Array.prototype.slice.call(arguments,0);
            // console.log(arguments, newArr, typeof newArr);
            // newArr.push(19999);
            // console.log(newArr)

            // 方式二： Array.from
            // var newArr = Array.from(arguments);

            // 方式三：扩展运算符 [...arguments]
            var newArr = [...arguments];
            return newArr.reduce(function (pre, cur) { return pre + cur }, 0);
        }
        var res = sum(1, 2, 3, 4, 5, 6);
        console.log(res);



        // 扩展运算 ...
        var arr = [1, 2, 3];
        var arr2 = [...arr];
        console.log(arr, arr2, arr === arr2);

    </script>
</body>

</html>